﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using Project.Module.Model;

namespace Project.Module.DAO.IBL
{
    public abstract class IBLTable<T, IdType>
    {
        public virtual string IdColumn { get { return "Id"; } }

        protected virtual string ConnectionString
        {
            get
            {
                return System.Web.Configuration.WebConfigurationManager.ConnectionStrings["ProjectDB"].ConnectionString.ToString(); 
            }
        }

        protected DBDataContext _context = null;

        public DBDataContext Context
        {
            get
            {
                if (_context == null)
                {

                    _context = new DBDataContext(this.ConnectionString);

                    _context.ObjectTrackingEnabled = true;
                    _context.DeferredLoadingEnabled = false;

                }
                return _context;
            }
        }

        protected System.Data.Linq.ITable Table
        {
            get
            {
                return this.Context.GetTable(typeof(T));
            }
        }

        protected string TableName
        {
            get
            {
                return ((System.Data.Linq.Mapping.TableAttribute)typeof(T).GetCustomAttributes(typeof(System.Data.Linq.Mapping.TableAttribute), true)[0]).Name;
            }
        }
    }
}
